package bairui.international.console.web.controller.personnel.employee;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.querydsl.QSort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.servlet.ModelAndView;

import com.lianjing.sh.project.config.web.Project_Config_Web_PageTemplate;
import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.module.context.ModuleContext;
import com.lianjing.sh.spring.web.controller.enhance.navigations.context.NavigationContext;
import com.querydsl.core.BooleanBuilder;

import bairui.international.console.web.controller.personnel.C_Personnel_Index_Left;
import bairui.international.model.domain.jpa.TB_Admin;
import bairui.international.service.Service_Admin;
import bairui.international.service.Service_Department;
import bairui.international.service.Service_Position;


/**
 * @generated
 *
 * C_Admin_Personnel_Employee_EditAccess
 *
 */
@Controller
public class C_Personnel_Employee_EditAccess
 extends SC_Personnel_Employee_EditAccess 
{
	
	@Autowired @Lazy private Service_Admin service_Admin;
	@Autowired @Lazy private Service_Department service_Department;
	@Autowired @Lazy private Service_Position service_Position;
	
	/**
	 * 访问编辑页面
	 */
	@Action(EditAccess.class)
	@GetMapping(EditAccess.RequestMappingValue)
	public ModelAndView editAccess(
		ModelMap map, HttpServletRequest request,
		NavigationContext navigationContext, ModuleContext moduleContext, 
		@PathVariable(name=EditAccess.PathVariableName.EmployeeId) long employeeId
	) throws Exception {
		/* 侧边栏 */
		C_Personnel_Index_Left.importPage(map);
		/* 模块 */
		TB_Admin bean = service_Admin.findById(employeeId);
			bean.setDepartments(service_Department.list(it->it.admins.any().eq(bean)));
			bean.setPositions(service_Position.list(it->it.admins.any().eq(bean)));
		moduleContext
			.addModule(this.module_Edit.module(
					bean,
					new C_Personnel_Employee_Edit.Edit.Operate() {
						@Override public Object getEmployeeId() {
							return employeeId;
						}
					}, 
					service_Department.list(
						it->new BooleanBuilder(), 
						it->new QSort(it.orderValue.desc())
					).getContent(), 
					service_Position.list(
						it->new BooleanBuilder(), 
						it->new QSort(it.orderValue.desc())
					).getContent()
				));
		//
		return Project_Config_Web_PageTemplate.Admin_Common(request);
	}
	

}


